package com.mdx.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mdx.bean.EventBean;
import com.mdx.dao.EventDao;
import com.mdx.service.IEventService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;

@Service
@Transactional
public class EventServiceImpl extends ServiceImpl<EventDao, EventBean> implements IEventService {
    @Override
    public EventBean findById(int eventId) {
        return this.baseMapper.selectById(eventId);
    }

    @Override
    public void updateStage(int eventId) {
        EventBean eventBean = this.getById(eventId);
        eventBean.setDisasterStage("无法解决，申请专家会商");
        this.updateById(eventBean);
    }

    @Override
    public IPage<EventBean> findByItem(int pageNO, int pageSize, String eventName, String disasterStage, String regionName, LocalDate start, LocalDate end) {
        IPage<EventBean> page = new Page<>(pageNO,pageSize);
        return this.baseMapper.findByItem(page,eventName,disasterStage,regionName,start,end);
    }

    @Override
    public void updateById(int eventId, String disasterStage, String preventionScheme) {
        EventBean eventBean = this.getById(eventId);
        eventBean.setDisasterStage(disasterStage);
        eventBean.setPreventionScheme(preventionScheme);
        this.updateById(eventBean);
    }

    @Override
    public void updateAdvice(int eventId, String advice) {
        EventBean eventBean = this.getById(eventId);
        eventBean.setAdvice(advice);
        this.updateById(eventBean);
    }
}
